// ESM
import autoLoad from '@fastify/autoload'
import { fileURLToPath } from 'url'
import path from 'path'
import fastify from 'fastify'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

const app = fastify({
  logger: true
})

app.register(autoLoad, {
  dir: path.join(__dirname, 'routes'),
  dirNameRoutePrefix: false // lack of prefix will mean no prefix, instead of directory name
})

app.listen({ host: '0.0.0.0', port: 3000 }, (err, address) => {
  if (err) {
    throw err
  }
  // Server is now listening on ${address}
})
